package com.flyco.modules.stm.controller;

import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.flyco.common.api.vo.Result;
import com.flyco.common.constant.CommonConstant;
import com.flyco.common.exception.FlycoException;
import com.flyco.common.system.query.QueryGenerator;
import com.flyco.common.aspect.annotation.AutoLog;
import com.flyco.common.system.vo.LoginUser;
import com.flyco.common.util.DateUtils;
import com.flyco.common.util.oConvertUtils;
import com.flyco.modules.oms.entity.OmsOrder;
import com.flyco.modules.oms.service.IOmsOrderService;
import com.flyco.modules.pms.entity.PmsProduct;
import com.flyco.modules.pms.entity.PmsSkuStock;
import com.flyco.modules.pms.service.IPmsProductService;
import com.flyco.modules.pms.service.IPmsSkuStockService;
import com.flyco.modules.stm.entity.*;
import com.flyco.modules.stm.model.*;
import com.flyco.modules.stm.service.*;

import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.flyco.modules.system.entity.SysUser;
import com.flyco.modules.system.service.ISysUserService;
import com.flyco.modules.task.service.SapTaskService;
import com.flyco.modules.ums.service.IUmsMemberReceiveAddress;
import lombok.extern.slf4j.Slf4j;
import com.flyco.common.system.base.controller.BaseController;
import com.flyco.poi.excel.ExcelImportUtil;
import com.flyco.poi.excel.def.NormalExcelConstants;
import com.flyco.poi.excel.entity.ExportParams;
import com.flyco.poi.excel.entity.ImportParams;
import com.flyco.poi.excel.view.EntityExcelView;

import net.sf.jsqlparser.statement.drop.Drop;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: 门店
 * @Author: flyco
 * @Date: 2020-09-18
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "门店")
@RestController
@RequestMapping("/f/stm/stmStoreInfo")
public class StmStoreInfoController extends BaseController<StmStoreInfo, IStmStoreInfoService> {
    @Autowired
    private IStmStoreInfoService stmStoreInfoService;
    @Autowired
    private IStmStoreSalesRelationService stmStoreSalesRelationService;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private IUmsMemberReceiveAddress umsMemberReceiveAddress;
    @Autowired
    private IPmsProductService pmsProductService;
    @Autowired
    private IPmsSkuStockService pmsSkuStockService;
    @Autowired
    private IStmChannelStoreRelationService stmChannelStoreRelationService;
    @Autowired
    private IStmDealerDiscountService stmDealerDiscountService;
    @Autowired
    private SapTaskService sapTaskService;
    @Autowired
    private IStmStoreInfoTraceService storeInfoTraceService;
    @Autowired
    private IOmsOrderService omsOrderService;

    /**
     * 分页列表查询
     *
     * @param stmStoreInfo
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "门店-分页列表查询")
    @ApiOperation(value = "门店-分页列表查询", notes = "门店-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(StmStoreInfo stmStoreInfo,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        stmStoreInfo.setPartnerId(sysUser.getPartnerId());
        if (stmStoreInfo.getName() != null && stmStoreInfo.getName().indexOf("*") == -1) {
            stmStoreInfo.setName("*" + stmStoreInfo.getName() + "*");
        }
        if (stmStoreInfo.getCompanyCode() != null && stmStoreInfo.getCompanyCode().indexOf("*") == -1) {
            stmStoreInfo.setCompanyCode("*" + stmStoreInfo.getCompanyCode() + "*");
        }
        if (stmStoreInfo.getId() != null && stmStoreInfo.getId().indexOf("*") == -1) {
            stmStoreInfo.setId("*" + stmStoreInfo.getId() + "*");
        }
        if (stmStoreInfo.getSaleRealName() != null && stmStoreInfo.getSaleRealName().indexOf("*") == -1) {
            stmStoreInfo.setSaleRealName("*" + stmStoreInfo.getSaleRealName() + "*");
        }
        if (stmStoreInfo.getAccount() != null && stmStoreInfo.getAccount().indexOf("*") == -1) {
            stmStoreInfo.setAccount("*" + stmStoreInfo.getAccount() + "*");
        }

        QueryWrapper<StmStoreInfo> queryWrapper = QueryGenerator.initQueryWrapper(stmStoreInfo, req.getParameterMap());
        queryWrapper.in("status", 0, 9)
                .orderByDesc("store_id");
        if (stmStoreInfo.getRelationStatus() != null && stmStoreInfo.getRelationStatus() == 1) {
            queryWrapper.isNull("parent_store_id");
        }
        Page<StmStoreInfo> page = new Page<StmStoreInfo>(pageNo, pageSize);
        IPage<StmStoreInfo> pageList = stmStoreInfoService.page(page, queryWrapper);

        return Result.ok(pageList);
    }

    /**
     * 分页列表查询
     */
    @AutoLog(value = "门店-分页列表查询")
    @ApiOperation(value = "门店-分页列表查询", notes = "门店-分页列表查询")
    @GetMapping(value = "/needApproveList")
    public Result<?> getNeedApproveList(StmStoreInfo stmStoreInfo,
                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                        HttpServletRequest req) {
        QueryWrapper<StmStoreInfo> queryWrapper = QueryGenerator.initQueryWrapper(stmStoreInfo, req.getParameterMap());
        queryWrapper.in("status", 1, 2)
                .orderByDesc("store_id");
        if (stmStoreInfo.getRelationStatus() != null && stmStoreInfo.getRelationStatus() == 1) {
            queryWrapper.isNull("parent_store_id");
        }
        Page<StmStoreInfo> page = new Page<StmStoreInfo>(pageNo, pageSize);
        IPage<StmStoreInfo> pageList = stmStoreInfoService.page(page, queryWrapper);

        return Result.ok(pageList);
    }

    /**
     * 分页列表查询
     */
    @AutoLog(value = "授信门店列表")
    @ApiOperation(value = "授信门店列表", notes = "授信门店列表")
    @GetMapping(value = "/creditList")
    public Result<?> getCreditList(StmStoreInfo stmStoreInfo,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        if (stmStoreInfo.getName() != null && stmStoreInfo.getName().indexOf("*") == -1) {
            stmStoreInfo.setName("*" + stmStoreInfo.getName() + "*");
        }
        QueryWrapper<StmStoreInfo> queryWrapper = QueryGenerator.initQueryWrapper(stmStoreInfo, req.getParameterMap());
        queryWrapper.ge("credit_limit", 0)
                .orderByDesc("store_id");
        if (stmStoreInfo.getRelationStatus() != null && stmStoreInfo.getRelationStatus() == 1) {
            queryWrapper.isNull("parent_store_id");
        }
        Page<StmStoreInfo> page = new Page<StmStoreInfo>(pageNo, pageSize);
        IPage<StmStoreInfo> pageList = stmStoreInfoService.page(page, queryWrapper);

        return Result.ok(pageList);
    }


    /**
     * 分页列表查询
     *
     * @return
     */
    @AutoLog(value = "门店-分页列表查询")
    @ApiOperation(value = "门店-分页列表查询", notes = "门店-分页列表查询")
    @GetMapping(value = "/getStoreAndChannel")
    public Result<?> getStoreAndChannel() {
        List<StmStoreInfo> list = stmStoreInfoService.getStoreAndChannel();
        return Result.ok(list);
    }


    /**
     * 查询所有可用门店
     *
     * @return
     */
    @AutoLog(value = "门店-查询所有可用门店")
    @ApiOperation(value = "门店-查询所有可用门店", notes = "门店-查询所有可用门店")
    @GetMapping(value = "/queryList")
    public Result<?> queryList() {
        LambdaQueryWrapper<StmStoreInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(StmStoreInfo::getStoreId, StmStoreInfo::getName);
        queryWrapper.ne(StmStoreInfo::getStatus, 0);
        queryWrapper.orderByDesc(StmStoreInfo::getStoreId);
        return Result.ok(stmStoreInfoService.list(queryWrapper));
    }

    /**
     * 发放开店大礼包
     *
     * @param stmStoreInfo
     * @return
     */
    @AutoLog(value = "门店-发放开店大礼包")
    @ApiOperation(value = "门店-发放开店大礼包", notes = "门店-发放开店大礼包")
    @PutMapping(value = "/generateSkuAndStock")
    public Result<?> generateSkuAndStock(@RequestBody StmStoreInfo stmStoreInfo) {
        if (oConvertUtils.isEmpty(stmStoreInfo) || !(oConvertUtils.isNotEmpty(stmStoreInfo.getStoreId()) || oConvertUtils.isNotEmpty(stmStoreInfo.getId())))
            return Result.error("参数错误!");
        if (oConvertUtils.isEmpty(stmStoreInfo.getStoreId())) {
            stmStoreInfo.setStoreId(Long.valueOf(stmStoreInfo.getId().split("-")[1]));
        }
        if (Objects.equals(0L, stmStoreInfo.getStoreId())) return Result.error("总仓没有大礼包!");
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        stmStoreInfoService.generateSku(sysUser.getPartnerId(), stmStoreInfo.getStoreId());
        stmStoreInfoService.generateStoreStock(sysUser.getPartnerId(), stmStoreInfo.getStoreId());
        return Result.ok("大礼包发放成功!");
    }


    /**
     * 添加
     *
     * @param stmStoreInfo
     * @return
     */
    @Deprecated
    @AutoLog(value = "经销商/门店-添加")
    @ApiOperation(value = "经销商/门店-添加", notes = "经销商/门店-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody StmStoreInfo stmStoreInfo) {
        stmStoreInfo.setPartnerId(4100L);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        stmStoreInfo.setStoreId(stmStoreInfoService.getNextStoreId());
        stmStoreInfo.setId(stmStoreInfo.getStoreId()+"");
        //速记生产
        stmStoreInfo.setCompanyCode(RandomUtil.randomNumbers(8));
        stmStoreInfoService.save(stmStoreInfo);
        //如果该手机号码不存在用户表，则新增进用户表
        if (userService.getUserByPhone(stmStoreInfo.getPhone()) == null) {
            SysUser newUser = new SysUser();
            newUser.setPartnerId(4100L);
            newUser.setStatus(1);
            newUser.setDelFlag(CommonConstant.DEL_FLAG_0);
            newUser.setPhone(stmStoreInfo.getPhone());
            newUser.setRealname(stmStoreInfo.getLinkName());
            newUser.setUsername(stmStoreInfo.getPhone());
            newUser.setType("b2b");
            newUser.setUserType(stmStoreInfo.getStoreType() != null && stmStoreInfo.getStoreType() == 2 ? 4 : 3);
            userService.save(newUser);
        }
        //新增供应商时，在供应商地址表中也增加一条默认地址，如果已经存在则删除后再重新插入。
        umsMemberReceiveAddress.InsertAddressWhenStoreInfoCreate(stmStoreInfo);

        //保存供应商与渠道的关系
        stmChannelStoreRelationService.saveByChannelIds(stmStoreInfo.getId(), stmStoreInfo.getStoreId(), stmStoreInfo.getChannelId());
        return Result.ok("添加成功！");
    }

    /**
     * 编辑
     *
     * @param stmStoreInfo
     * @return
     */
    @Deprecated
    @AutoLog(value = "门店-编辑")
    @ApiOperation(value = "门店-编辑", notes = "门店-编辑")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody StmStoreInfo stmStoreInfo) {

        StmStoreInfo storeInfo = stmStoreInfoService.getById(stmStoreInfo.getId());
        if (!Objects.equals(storeInfo.getSaleUserId(), stmStoreInfo.getSaleUserId())) {
            //修改销售人员时，同步修改名称及金蝶编号
            SysUser userInfo = userService.getById(stmStoreInfo.getSaleUserId());
            if (userInfo != null) {
                stmStoreInfo.setSaleRealName(userInfo.getRealname());
                stmStoreInfo.setSaleNumber(userInfo.getJdCode());
                stmStoreInfo.setDpFlag(stmStoreInfo.getDpFlag() + 1);
            }
        }
        if (!Objects.equals(storeInfo.getChannelId(), stmStoreInfo.getChannelId())) {
            stmStoreInfo.setDpFlag(stmStoreInfo.getDpFlag() + 1);
        }
        stmStoreInfoService.updateById(stmStoreInfo);

        //编辑供应商时，在供应商地址表中也更新对于的默认地址。
        umsMemberReceiveAddress.updateAddressWhenStoreInfoUpdate(stmStoreInfo);

        //保存供应商与渠道的关系
        stmChannelStoreRelationService.saveByChannelIds(stmStoreInfo.getId(), stmStoreInfo.getStoreId(), stmStoreInfo.getChannelId());
        return Result.ok("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @Deprecated
    @AutoLog(value = "门店-通过id删除")
    @ApiOperation(value = "门店-通过id删除", notes = "门店-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        StmStoreInfo stmStoreInfo = stmStoreInfoService.getById(id);
        stmStoreSalesRelationService.deleteByMainId(stmStoreInfo.getStoreId());
        stmStoreInfoService.removeById(id);
        return Result.ok("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @Deprecated
    @AutoLog(value = "门店-批量删除")
    @ApiOperation(value = "门店-批量删除", notes = "门店-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.stmStoreInfoService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功！");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "门店-通过id查询")
    @ApiOperation(value = "门店-通过id查询", notes = "门店-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        StmStoreInfo stmStoreInfo = stmStoreInfoService.getById(id);
        return Result.ok(stmStoreInfo);
    }

    //===========================以下是子表信息操作相关API====================================

    /**
     * 通过主表id查询门店店员关联
     *
     * @param stmStoreSalesRelation
     * @return
     */
    @AutoLog(value = "门店店员关联-通过主表id查询")
    @ApiOperation(value = "门店店员关联-通过主表id查询", notes = "门店店员关联-通过主表id查询")
    @GetMapping(value = "/listStmStoreSalesRelationByMainId")
    public Result<?> listStmStoreSalesRelationByMainId(StmStoreSalesRelation stmStoreSalesRelation,
                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                       HttpServletRequest req) {
        if (stmStoreSalesRelation.getStoreId() != null) {
            QueryWrapper<StmStoreSalesRelation> queryWrapper = QueryGenerator.initQueryWrapper(stmStoreSalesRelation, req.getParameterMap());
            Page<StmStoreSalesRelation> page = new Page<StmStoreSalesRelation>(pageNo, pageSize);
            IPage<StmStoreSalesRelation> pageList = stmStoreSalesRelationService.getStoreSalesRelationPage(page, queryWrapper);
            return Result.ok(pageList);
        } else {
            return Result.error("请选择店铺");
        }
    }

    /**
     * 通过主表id查询门店店员关联
     *
     * @param
     * @return
     */
    @AutoLog(value = "经销商关联网点-通过主表id查询")
    @ApiOperation(value = "经销商关联网点-通过主表id查询", notes = "经销商关联网点-通过主表id查询")
    @GetMapping(value = "/listStmStoreByMainId")
    public Result<?> listStmStoreByMainId(StmStoreInfo stmStore,
                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                          HttpServletRequest req) {
        LambdaQueryWrapper<StmStoreInfo> queryWrapper = new LambdaQueryWrapper<StmStoreInfo>();
        queryWrapper.eq(StmStoreInfo::getParentStoreId, stmStore.getStoreId()).eq(StmStoreInfo::getStoreType, 2);
        Page<StmStoreInfo> page = new Page<StmStoreInfo>(pageNo, pageSize);
        IPage<StmStoreInfo> pageList = stmStoreInfoService.page(page, queryWrapper);
        return Result.ok(pageList);

    }

    /**
     * 通过主表id查询门店店员关联
     *
     * @param storeId
     * @return
     */
    @GetMapping(value = "/queryStoreSalesRelationByMainId")
    public Result<?> queryPmsSkuStockByMainId(@RequestParam(name = "storeId", required = true) Long storeId) {
        List<StmStoreSalesRelation> salesRelations = stmStoreSalesRelationService.selectByMainId(storeId);
        return Result.ok(salesRelations);
    }

    /**
     * 添加门店店员关联
     *
     * @param model
     * @return
     */
    @AutoLog(value = "门店店员关联-添加")
    @ApiOperation(value = "门店店员关联-添加", notes = "门店店员关联-添加")
    @PostMapping(value = "/addStmStoreSalesRelation")
    public Result<?> addStmStoreSalesRelation(@RequestBody StmStoreSalesRelationModel model) {
        if (null != model && null != model.getSalesIdList() && null != model.getStoreId()) {
            List<StmStoreSalesRelation> dbSalesRelations = stmStoreSalesRelationService.selectByMainId(model.getStoreId());
            List<Long> dbList = dbSalesRelations.stream().map(StmStoreSalesRelation::getSalesId).collect(Collectors.toList());
            //List<StmStoreSalesRelation> mixes = dbSalesRelations.stream().filter(r->model.getSalesIdList().contains(r.getId())).collect(Collectors.toList());
            List<StmStoreSalesRelation> updateRelations = dbSalesRelations.stream()
                    .filter(r -> model.getSalesIdList().contains(r.getSalesId()))
                    .filter(q -> q.getDelFlag() == 1)
                    .map(one -> {
                        StmStoreSalesRelation s = new StmStoreSalesRelation();
                        s.setDelFlag(0);
                        s.setId(one.getId());
                        return s;
                    }).collect(Collectors.toList());
            if (updateRelations.size() > 0) {
                stmStoreSalesRelationService.updateBatchById(updateRelations);
            }
            //List<Long> mixes =  model.getSalesIdList().stream().filter(item -> dbList.contains(item)).collect(Collectors.toList());

            model.getSalesIdList().removeAll(dbList);
            List<StmStoreSalesRelation> salesRelations = new ArrayList<>();
            for (Long salesId : model.getSalesIdList()) {
                StmStoreSalesRelation salesRelation = new StmStoreSalesRelation();
                salesRelation.setStoreId(model.getStoreId());
                salesRelation.setSalesId(salesId);
                salesRelations.add(salesRelation);
            }
            stmStoreSalesRelationService.saveBatch(salesRelations);
            return Result.ok("门店店员添加成功！");
        }
        return Result.error("门店店员添加失败！");
    }

    /**
     * 添加门店店员关联
     *
     * @param model
     * @return
     */
    @AutoLog(value = "经销商关联门店-添加")
    @ApiOperation(value = "经销商关联门店-添加", notes = "经销商关联门店-添加")
    @PostMapping(value = "/addStmStoreRelation")
    public Result<?> addStmStoreRelation(@RequestBody StmStoreRelationModel model) {
        if (null != model && null != model.getSalesIdList() && null != model.getStoreId()) {
            List<StmStoreSalesRelation> salesRelations = new ArrayList<>();
            for (String salesId : model.getSalesIdList()) {
                StmStoreInfo stmStoreInfo = stmStoreInfoService.getById(salesId);
                if (stmStoreInfo.getParentStoreId() == null || stmStoreInfo.getParentStoreId() == -1l) {
                    stmStoreInfo.setParentStoreId(model.getStoreId());
                    stmStoreInfoService.updateById(stmStoreInfo);
                }
            }
            return Result.ok("经销商关联网点添加成功！");
        }
        return Result.error("经销商关联网点添加失败！");
    }

    /**
     * 编辑门店店员关联
     *
     * @param stmStoreSalesRelation
     * @return
     */
    @AutoLog(value = "门店店员关联-职务调整")
    @ApiOperation(value = "门店店员关联-职务调整", notes = "门店店员关联-职务调整")
    @PutMapping("/editStmStoreSalesRelation")
    public Result<?> editStmStoreSalesRelation(@RequestBody StmStoreSalesRelation stmStoreSalesRelation) {
        stmStoreSalesRelationService.updateById(stmStoreSalesRelation);
        return Result.ok("职务调整成功！");
    }

    /**
     * 通过id删除门店店员关联
     *
     * @param id
     * @return
     */
    @AutoLog(value = "门店店员关联-通过id删除")
    @ApiOperation(value = "门店店员关联-通过id删除", notes = "门店店员关联-通过id删除")
    @DeleteMapping(value = "/deleteStmStoreSalesRelation")
    public Result<?> deleteStmStoreSalesRelation(@RequestParam(name = "id", required = true) String id) {
        stmStoreSalesRelationService.removeById(id);
        return Result.ok("删除门店店员关联成功！");
    }

    /**
     * 通过id删除门店店员关联
     *
     * @param id
     * @return
     */
    @AutoLog(value = "取消经销商与门店关联-通过id删除")
    @ApiOperation(value = "取消经销商与门店关联--通过id删除", notes = "取消经销商与门店关联--通过id删除")
    @DeleteMapping(value = "/deleteStmStoreRelation")
    public Result<?> deleteStmStoreRelation(@RequestParam(name = "id", required = true) String id) {
        StmStoreInfo stmStoreInfo = stmStoreInfoService.getById(id);
        stmStoreInfo.setParentStoreId(null);
        stmStoreInfoService.updateById(stmStoreInfo);
        return Result.ok("取消经销商与网点关联成功！");
    }

    /**
     * 批量删除门店店员关联
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "门店店员关联-批量删除")
    @ApiOperation(value = "门店店员关联-批量删除", notes = "门店店员关联-批量删除")
    @DeleteMapping(value = "/deleteBatchStmStoreSalesRelation")
    public Result<?> deleteBatchStmStoreSalesRelation(@RequestParam(name = "ids", required = true) String ids) {
        if (ids == null || "".equals(ids.trim())) {
            return Result.error("参数不识别！");
        }
        this.stmStoreSalesRelationService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功！");

    }


    /**
     * 导出excel
     *
     * @param request
     * @param stmStoreInfo
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, StmStoreInfo stmStoreInfo) {

        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<StmStoreInfo> queryWrapper = QueryGenerator.initQueryWrapper(stmStoreInfo, request.getParameterMap());
        queryWrapper.orderByDesc("store_id");
        if (stmStoreInfo.getRelationStatus() != null && stmStoreInfo.getRelationStatus() == 1) {
            queryWrapper.isNull("parent_store_id");
        }

        List<StmStoreInfo> list = stmStoreInfoService.list(queryWrapper);
        List<StmStoreInfoExcel> excelList = new ArrayList<>();
        list.forEach(o -> {
            StmStoreInfoExcel stmStoreInfoExcel = new StmStoreInfoExcel();
            BeanUtils.copyProperties(o, stmStoreInfoExcel);
            stmStoreInfoExcel.setStatusName(o.getStatus().equals(9) ? "全面开放" : "已关闭");
            excelList.add(stmStoreInfoExcel);
        });

        //Step.3 调用AutoPoi导出Excel
        ModelAndView mv = new ModelAndView(new EntityExcelView());
        mv.addObject(NormalExcelConstants.FILE_NAME, "经销商");
        mv.addObject(NormalExcelConstants.CLASS, StmStoreInfoExcel.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("经销商列表", "导出人:" + sysUser.getRealname(), "经销商"));
        mv.addObject(NormalExcelConstants.DATA_LIST, excelList);
        return mv;
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @ApiOperation("通过excle导入经销商信息")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, StmStoreInfo.class);
    }

    /**
     * 通过供应商显示可售物料
     */
    @GetMapping(value = "/listPmsSkuStockByStoreId")
    public Result<?> listPmsSkuStockByStoreId(PmsSkuStock pmsSkuStock,
                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                              HttpServletRequest req) {
        if (pmsSkuStock.getStoreId() != null) {
            QueryWrapper<PmsSkuStock> queryWrapper = QueryGenerator.initQueryWrapper(pmsSkuStock, req.getParameterMap());

            Page<PmsSkuStock> page = new Page<PmsSkuStock>(pageNo, pageSize);
            IPage<PmsSkuStock> pageList = pmsSkuStockService.page(page, queryWrapper);
            if (pageList.getTotal() > 0) {

                List<PmsProduct> productList = pmsProductService.list();
                Map<Long, PmsProduct> productMap = productList.stream().collect(Collectors.toMap(PmsProduct::getId, pmsProduct -> pmsProduct, (key1, key2) -> key2));

                pageList.getRecords().forEach(stock -> {
                    if (oConvertUtils.isNotEmpty(stock.getProductId())) {
                        if (productMap.containsKey(stock.getProductId())) {
                            stock.setProductId_dictText(productMap.get(stock.getProductId()).getName());
                        } else {
                            if (Objects.equals(0L, stock.getStoreId())) {
                                stock.setProductId_dictText("");
                            }
                        }
                    }
                });
            }
            return Result.ok(pageList);
        } else {
            return Result.error("请选择经销商");
        }
    }


    /**
     * 通过skuId删除经销商可售商品
     */
    @AutoLog(value = "通过skuId删除经销商可售商品")
    @ApiOperation(value = "通过skuId删除经销商可售商品", notes = "通过skuId删除经销商可售商品")
    @DeleteMapping(value = "/deleteSkuById")
    public Result<?> deleteSkuById(@RequestParam(name = "id", required = true) String id) {
        pmsSkuStockService.removeById(id);
        return Result.ok("删除成功！");
    }

    /**
     * 批量删除经销商商品
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "批量删除经销商商品")
    @ApiOperation(value = "批量删除经销商商品", notes = "批量删除经销商商品")
    @DeleteMapping(value = "/deleteBatchSkuByIds")
    public Result<?> deleteBatchSkuByIds(@RequestParam(name = "ids", required = true) String ids) {
        if (ids == null || "".equals(ids.trim())) {
            return Result.error("参数不识别！");
        }
        this.pmsSkuStockService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功！");

    }

    /**
     * 门店增加可售商品
     */
    @AutoLog(value = "门店增加可售商品")
    @ApiOperation(value = "门店增加可售商品", notes = "门店增加可售商品")
    @PostMapping(value = "/AddProductSku")
    public Result<?> AddProductSku(@RequestBody PmsSkuStock pmsSkuStock) {
        if (pmsSkuStock == null || StringUtils.isEmpty(pmsSkuStock.getSkuCode())) {
            return Result.error("参数错误！");
        }
        PmsSkuStock skuStock;
        if (pmsSkuStock.getId() != null && pmsSkuStock.getId() > 0) {
            skuStock = pmsSkuStockService.getById(pmsSkuStock.getId());
            skuStock.setPrice(pmsSkuStock.getPrice());
        } else {

            //判断是否已经存在，不存在才能添加
            LambdaQueryWrapper<PmsSkuStock> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(PmsSkuStock::getStoreId, pmsSkuStock.getStoreId()).eq(PmsSkuStock::getProductId, pmsSkuStock.getProductId());
            PmsSkuStock stock = pmsSkuStockService.getOne(wrapper);
            if (stock != null && stock.getId() > 0) {
                return Result.error("经销商已存在该商品，不能继续添加！");
            }
            PmsProduct product = pmsProductService.getById(pmsSkuStock.getProductId());
            skuStock = getSkuStock(product);
            skuStock.setStoreId(pmsSkuStock.getStoreId());
            skuStock.setPrice(pmsSkuStock.getPrice());
        }

        this.pmsSkuStockService.saveOrUpdate(skuStock);
        return Result.ok("新增完成！");
    }


    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importPmsSkuStockExcel", method = RequestMethod.POST)
    public Result<?> importPmsSkuStockExcel(HttpServletRequest request, HttpServletResponse response) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        Long storeId = Long.valueOf(request.getParameter("storeId"));
        StmStoreInfo storeInfo = stmStoreInfoService.getByStoreId(storeId);
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            ImportParams params = new ImportParams();
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<PmsSkuStock> list = ExcelImportUtil.importExcel(file.getInputStream(), PmsSkuStock.class, params);
                List<PmsSkuStock> updateStock = new ArrayList<>();
                for (PmsSkuStock stock : list) {
                    LambdaQueryWrapper<PmsProduct> wrapper = new LambdaQueryWrapper<>();
                    wrapper.eq(PmsProduct::getSkuCode, stock.getSkuCode());
                    PmsProduct productInfo = pmsProductService.getOne(wrapper);
                    if (productInfo == null || StringUtils.isBlank(productInfo.getProductSn())) {
                        continue;
                    }
                    if (!storeInfo.getBrandCategory().equals(productInfo.getBrandCategory())) {
                        continue;
                    }
                    PmsSkuStock skuStock = getSkuStock(productInfo);
                    skuStock.setStoreId(storeId);
                    skuStock.setPrice(stock.getPrice());
                    //判断是否已经存在，不存在才能添加
                    LambdaQueryWrapper<PmsSkuStock> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                    lambdaQueryWrapper.eq(PmsSkuStock::getStoreId, storeId).eq(PmsSkuStock::getSkuCode, stock.getSkuCode());
                    PmsSkuStock stockInfo = pmsSkuStockService.getOne(lambdaQueryWrapper);
                    if (stockInfo != null && stockInfo.getId() > 0) {
                        //说明已经存在该商品，需要进行更新处理
                        skuStock.setId(stockInfo.getId());
                    }
                    updateStock.add(skuStock);
                }
                pmsSkuStockService.saveOrUpdateBatch(updateStock);
                return Result.ok("文件导入成功！数据行数:" + updateStock.size());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("文件导入失败:" + e.getMessage());
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.ok("文件导入失败！");
    }

    private PmsSkuStock getSkuStock(PmsProduct product) {

        PmsSkuStock skuStock = new PmsSkuStock();
        skuStock.setProductId(product.getId());
        skuStock.setProductSn(product.getProductSn());
        skuStock.setSkuCode(product.getSkuCode());
        skuStock.setStorePrice(product.getPrice());
        skuStock.setStock(10000);
        skuStock.setLockStock(0);
        skuStock.setCancelFlag(0);
        skuStock.setVersion(0L);
        skuStock.setCreateBy("system");
        skuStock.setCreateTime(DateTime.now());
        return skuStock;
    }

    @RequestMapping(value = "/download")
    public void download(HttpServletRequest req, HttpServletResponse res) {
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {

            inputStream = this.getClass().getResourceAsStream("/templates/经销商可售物料模板.xlsx");
            outputStream = res.getOutputStream();
            int temp = 0;
            while ((temp = inputStream.read()) != -1) {
                outputStream.write(temp);
            }
            res.setContentType("application/force-download");// 设置强制下载不打开
            res.addHeader("Content-Disposition", "attachment;fileName=" + new String("入库明细模板.xlsx".getBytes("UTF-8"), "iso-8859-1"));
            res.setHeader("content-type", "text/html;charset=UTF-8");
            res.setCharacterEncoding("UTF-8");
        } catch (Exception e) {
            log.error("", e);
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return;
    }

    /**
     * 设置经销商账号
     */
    @AutoLog(value = "设置经销商账号")
    @ApiOperation(value = "设置经销商账号", notes = "设置经销商账号")
    @PostMapping(value = "/setAccount")
    public Result<?> setAccount(@RequestBody DealerAccountDTO accountDTO) {
        if (accountDTO == null || StringUtils.isEmpty(accountDTO.getPassword()) || StringUtils.isEmpty(accountDTO.getUsername())
                || StringUtils.isEmpty(accountDTO.getConfirmpassword())) {
            return Result.error("参数错误！");
        }
        if (!accountDTO.getPassword().equals(accountDTO.getConfirmpassword())) {
            return Result.error("两次输入的密码不一样！");
        }

        List<Long> storeId = new ArrayList<>();
        storeId.add(accountDTO.getStoreId());
        List<StmStoreInfo> stmStoreInfoList = stmStoreInfoService.getStoreInfoList(storeId);
        if (stmStoreInfoList == null) {
            return Result.error("未找到经销商信息");
        }
        StmStoreInfo storeInfo = stmStoreInfoList.get(0);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        //设置用户表的账号和密码信息
        Integer userType = storeInfo.getStoreType().equals(1) ? 3 : 4;
        String realName = storeInfo.getName();
        Result result = userService.addUserOrUpdatePwd(accountDTO, userType, realName);
        if (result.isSuccess()) {

            //给经销商或网点绑定账号
            storeInfo.setAccount(accountDTO.getUsername());
            stmStoreInfoService.updateById(storeInfo);
            return Result.ok("设置成功");
        } else {
            return result;
        }
    }


    /**
     * 添加
     */
    @Deprecated
    @AutoLog(value = "经销商-审核")
    @ApiOperation(value = "经销商-审核", notes = "经销商-审核")
    @PostMapping(value = "/approve")
    public Result<?> approve(@RequestBody StmStoreInfo stmStoreInfo) {

        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        StmStoreInfo storeInfo = stmStoreInfoService.getById(stmStoreInfo.getId());
        if (storeInfo == null) {
            return Result.error("经销商未找到！");
        }
        if (!storeInfo.getStatus().equals(1)) {
            return Result.error("数据已过期，请刷新页面！");
        }
        storeInfo.setStatus(stmStoreInfo.getStatus());
        storeInfo.setApproveName(sysUser.getRealname());
        storeInfo.setApproveTime(new Date());
        storeInfo.setApproveReason(stmStoreInfo.getApproveReason());
        stmStoreInfoService.updateById(storeInfo);

        if (stmStoreInfo.getStatus() == 9) {
            //在供应商地址表中也增加一条默认地址，如果已经存在则删除后再重新插入。
            umsMemberReceiveAddress.InsertAddressWhenStoreInfoCreate(stmStoreInfo);
        }

        if (stmStoreInfo.getStatus() == 2) {
            stmStoreInfoService.sendMailForApprove(storeInfo);
        }
        return Result.ok("审批成功！");
    }


    @AutoLog(value = "经销商详情")
    @ApiOperation(value = "经销商详情", notes = "经销商详情")
    @GetMapping(value = "/storeInfo/{storeId}/{orderId}")
    public Result<?> getStoreInfo(@PathVariable("storeId") Long storeId, @PathVariable("orderId") String orderId) {
        //先更新经销商可用余额
        sapTaskService.updateBalance(storeId.toString());
        StmStoreInfo storeInfo = stmStoreInfoService.getByStoreId(storeId);
        //增加折扣信息的返回 by martin 2024-04-16
        if (storeInfo != null) {
            StmDealerDiscount stmDealerDiscount = stmDealerDiscountService.getDiscountByStoreId(storeInfo);
            if (storeInfo.getRemainCreditLimit() != null) {
                stmDealerDiscount.setBalance(storeInfo.getRemainCreditLimit());
            } else {
                stmDealerDiscount.setBalance(BigDecimal.ZERO);
            }
            List<OmsOrder> orderList = omsOrderService.getOrderListByStoreId(storeInfo.getId(), orderId);
            if (orderList != null && !orderList.isEmpty()) {
                BigDecimal productOccupy = orderList.stream().map(OmsOrder::getProductDiscountAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal promotionOccupy = orderList.stream().map(OmsOrder::getPromotionDiscountAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal adjustOccupy = orderList.stream().map(OmsOrder::getAdjustDiscountAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal missionOccupy = orderList.stream().map(OmsOrder::getMissionDiscountAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                if (stmDealerDiscount.getProductRemainAmount().compareTo(productOccupy) >= 0) {
                    stmDealerDiscount.setProductRemainAmount(stmDealerDiscount.getProductRemainAmount().subtract(productOccupy));
                }
                if (stmDealerDiscount.getPromotionRemainAmount().compareTo(promotionOccupy) >= 0) {
                    stmDealerDiscount.setPromotionRemainAmount(stmDealerDiscount.getPromotionRemainAmount().subtract(promotionOccupy));
                }
                if (stmDealerDiscount.getAdjustRemainAmount().compareTo(adjustOccupy) >= 0) {
                    stmDealerDiscount.setAdjustRemainAmount(stmDealerDiscount.getAdjustRemainAmount().subtract(adjustOccupy));
                }
                if (stmDealerDiscount.getMissionRemainAmount().compareTo(missionOccupy) >= 0) {
                    stmDealerDiscount.setMissionRemainAmount(stmDealerDiscount.getMissionRemainAmount().subtract(missionOccupy));
                }
            }
            storeInfo.setDealerDiscount(stmDealerDiscount);
        }
        return Result.ok(storeInfo);
    }


    @AutoLog(value = "经销商授信审核")
    @ApiOperation(value = "经销商授信审核", notes = "经销商授信审核")
    @PostMapping(value = "/creditApprove")
    public Result<?> creditApprove(@RequestBody StmStoreInfo stmStoreInfo) {

        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        StmStoreInfo storeInfo = stmStoreInfoService.getById(stmStoreInfo.getId());
        if (storeInfo == null) {
            return Result.error("经销商未找到！");
        }
        if (!storeInfo.getCreditStatus().equals(0)) {
            return Result.error("数据已过期，请刷新页面！");
        }
        storeInfo.setCreditStatus(stmStoreInfo.getCreditStatus());
        storeInfo.setCreditApproveName(sysUser.getRealname());
        storeInfo.setCreditEnableStatus("1");
        storeInfo.setCreditApproveTime(new Date());
        storeInfo.setCreditApproveReason(stmStoreInfo.getCreditApproveReason());
        stmStoreInfoService.updateById(storeInfo);

        return Result.ok("审批成功！");
    }

    /**
     * 获取门店列表-包含是否配置订单起订信息
     */
    @AutoLog(value = "获取门店列表-包含是否配置订单起订信息")
    @ApiOperation(value = "获取门店列表-包含是否配置订单起订信息")
    @GetMapping(value = "/storeListAndOrderDistance")
    public Result<?> queryStoreListAndOrderDistance() {
        List<StmStoreInfo> storeInfoList = stmStoreInfoService.queryStoreListAndOrderDistance();

        List<DropDownVO> dropDownList = new ArrayList<>();
        DropDownVO dropDownVO;
        for (StmStoreInfo storeInfo : storeInfoList) {
            dropDownVO = new DropDownVO();
            dropDownVO.setLabel(storeInfo.getName());
            dropDownVO.setValue(storeInfo.getId());
            dropDownList.add(dropDownVO);
        }

        return Result.ok(dropDownList);
    }

    @AutoLog(value = "更新经销商授信启用状态")
    @ApiOperation(value = "更新经销商授信启用状态", notes = "更新经销商授信启用状态")
    @PostMapping(value = "/updateCreditEnableStatus")
    public Result<?> updateCreditEnableStatus(@RequestBody StmStoreInfo stmStoreInfo) {

        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        StmStoreInfo storeInfo = new StmStoreInfo();
        storeInfo.setCreditEnableStatus(stmStoreInfo.getCreditEnableStatus());
        storeInfo.setUpdateTime(new Date());
        storeInfo.setId(stmStoreInfo.getId());
        stmStoreInfoService.updateById(storeInfo);

        return Result.ok("修改成功！");
    }

    @AutoLog(value = "门店-分页列表查询")
    @ApiOperation(value = "门店-分页列表查询", notes = "门店-分页列表查询")
    @GetMapping(value = "/storeListByStoreIds")
    public Result<?> getStoreListByStoreIds(@RequestParam("storeIdList") String storeIds) {

        List<Long> storeIdList = Arrays.asList(storeIds.split(",")).stream()
                .map(o -> {
                    Long id = Long.valueOf(o);
                    return id;
                }).collect(Collectors.toList());

        List<StmStoreInfo> list = stmStoreInfoService.getStoreInfoList(storeIdList);
        return Result.ok(list);
    }

    @AutoLog(value = "查询销售公司列表")
    @ApiOperation(value = "查询销售公司列表", notes = "查询销售公司列表")
    @GetMapping(value = "/companyList")
    public Result<?> getCompanyList() {

        List<StmStoreInfo> list = stmStoreInfoService.getCompanyList();
        return Result.ok(list);
    }

    @AutoLog(value = "更新经销商可用余额")
    @ApiOperation(value = "更新经销商可用余额", notes = "更新经销商可用余额")
    @GetMapping(value = "/updateRemainAmount")
    public Result<?> updateRemainAmount(@RequestParam(name = "storeId", required = true) String storeId) {
        if (!StringUtils.isEmpty(storeId)) {
            sapTaskService.updateBalance(storeId);
        }
        return Result.ok("修改成功！");
    }

    @AutoLog(value = "根据名字查询经销商列表")
    @ApiOperation(value = "根据名字查询经销商列表", notes = "根据名字查询经销商列表")
    @GetMapping(value = "/getDropDownList")
    public Result<?> getDropDownList(@RequestParam(name = "storeName") String storeName) {
        List<DropDownVO> resultList = new ArrayList<>();
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<StmStoreInfo> storeInfoList = stmStoreInfoService.getStoreListByName(storeName, sysUser.getPartnerId());
        if (storeInfoList != null && !storeInfoList.isEmpty()) {
            storeInfoList.forEach(x -> {
                DropDownVO vo = new DropDownVO();
                vo.setLabel(x.getName());
                vo.setValue(x.getCompanyCode());
                resultList.add(vo);
            });
        }
        List<DropDownVO> newList = resultList.stream().distinct().collect(Collectors.toList());
        return Result.ok(newList);
    }

    @AutoLog(value = "更新经销商禁用状态")
    @ApiOperation(value = "更新经销商禁用状态", notes = "更新经销商禁用状态")
    @PostMapping(value = "/updateDisabledStatus")
    public Result<?> updateDisabledStatus(@RequestBody StmStoreInfo stmStoreInfo) {
        if (stmStoreInfo.getDisabledStatus().equals(1) && stmStoreInfo.getDisabledTime() == null) {
            throw new FlycoException("请选择禁用日期！");
        }
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        UpdateWrapper<StmStoreInfo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", stmStoreInfo.getId());
        //启用的时候立即修改为启用状态并清空禁用时间
        if (stmStoreInfo.getDisabledStatus().equals(0)) {
            updateWrapper.set("disabled_status", 0);
            updateWrapper.set("disabled_time", null);
        } else {
            updateWrapper.set("disabled_time", stmStoreInfo.getDisabledTime());
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            //如果禁用日期是今天，直接禁用
            if (dateFormat.format(stmStoreInfo.getDisabledTime()).equals(dateFormat.format(new Date())) || stmStoreInfo.getDisabledTime().compareTo(new Date()) < 0) {
                updateWrapper.set("disabled_status", 1);
            }
        }
        updateWrapper.set("update_by", sysUser.getRealname());
        updateWrapper.set("update_time", new Date());
        stmStoreInfoService.update(updateWrapper);

        //写入变更日志
        StmStoreInfoTrace trace = new StmStoreInfoTrace();
        trace.setStoreId(stmStoreInfo.getId());
        trace.setLabel("禁用状态修改");
        String statusName = stmStoreInfo.getDisabledStatus() == 0 ? "启用" : "禁用";
        String dateString = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        String contentMsg = dateString + " " + sysUser.getRealname() + "修改经销商状态为【" + statusName + "】";
        if (statusName.equals("禁用")) {
            contentMsg += "，禁用日期为：【" + DateUtil.format(stmStoreInfo.getDisabledTime(), "yyyy-MM-dd") + "】";
        }
        trace.setContent(contentMsg);
        trace.setCreateBy(sysUser.getRealname());
        trace.setCreateTime(new Date());
        storeInfoTraceService.save(trace);
        return Result.ok("修改成功！");
    }
}
